Repository navigation
BIP-375: correct labeled test vectors to include labeled-spend key in PSBT_OUT_SP_V0_INFO - #2207
Conversation
|
cc BIP Owners for review: @andrewtoth, @achow101, @josibake |
|
Implementer's note. btclib has a BIP375 implementation and currently Measured, in both directions, with
No invalid vector changes verdict under either rule. The two invalid Two remarks, one per half of the PR. The On the ordering half, a question about the rule rather than about which
So index order looks like the cheaper rule, and it is what all three We have no stake beyond interoperability and will follow whichever way Unrelated and not touched here, noted while checking the above: L149 Edited: the last paragraph originally called this an inconsistency about |
|
@fametrano Thank you for the report. It is a little hard to understand, can you summarize more concisely in your own words, please? |
|
@jonatack in short: I support the labeled-spend-key half of this PR, it looks right regardless of the ordering question. The sort half is the alternative to #2256, which changes the text to the index order the current validator and vectors already follow; either direction removes the contradiction, and the owners' preference decides which of the two lands. The measurement in both directions is reproducible from the diff posted on #2256. |
|
Partial nACK, to make my note above explicit: nACK the ordering half, ACK the ACK the labeled-spend-key fix. Carrying the labeled spend key is correct and is needed whichever ordering rule wins; this half should land. nACK the switch to lexicographic ordering. As measured above: the k assignment is invisible to a BIP352 receiver and serves only Signer/Extractor determinism, so any deterministic rule is equally correct and the choice is one of cost. Lexicographic's one advantage — invariance under output reordering — is unavailable here: L185 makes a Signer clear Outputs Modifiable when it sets a script, and Could this be two PRs? The two fixes are independent and only the ordering one is contested. Splitting them lets the |
8f7b632 to
9514ecc
Compare
|
Rebased on master to resolve the conflict after #2286 "BIP375: validate PSBT_OUT_SP_V0_LABEL length". |
|
@andrewtoth: Does that look good to you? |
|
Updated the labels for the deputization of @macgyver13. |
jonatack
left a comment
There was a problem hiding this comment.
ACK
I think I prefer aligning the reference to the existing prose (this PR) rather than rewriting the rule (#2256). It seems that Sparrow 2.5.5, SeedSigner, Caravan, and Coldcard followed the text, while btclib followed the vectors (simpler, using already-present output indices)?
|
|
||
| Compute the PSBT_OUT_SCRIPT using the procedure in [https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#creating-outputs BIP352] but substituting ''a·B<sub>scan</sub>'' with the PSBT_GLOBAL_SP_ECDH_SHARE for that scan key if available, or the sum of all PSBT_IN_SP_ECDH_SHAREs from eligible inputs for that scan key. | ||
| If there are multiple silent payment codes with the same scan key, sort the codes lexicographically in ascending order to determine the ordering of the ''k'' value. | ||
| If there are multiple silent payment codes with both the same scan and spend keys, sort the subgroup by output index in ascending order. |
There was a problem hiding this comment.
Would it be useful to describe the sort key in the BIP to avoid ambiguity? for instance
Compute the PSBT_OUT_SCRIPT using the procedure in [https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#creating-outputs BIP352] but substituting ''a·B<sub>scan</sub>'' with the PSBT_GLOBAL_SP_ECDH_SHARE for that scan key if available, or the sum of all PSBT_IN_SP_ECDH_SHAREs from eligible inputs for that scan key.
If there are multiple silent payment codes with the same scan key, sort the codes lexicographically in ascending order to determine the ordering of the ''k'' value.
+The sort key is the 66-byte serialized <tt>PSBT_OUT_SP_V0_INFO</tt> (33-byte scan key followed by 33-byte spend key).
If there are multiple silent payment codes with both the same scan and spend keys, sort the subgroup by output index in ascending order.
===Transaction Extractor===or
====Computing the Output Scripts====
Compute the PSBT_OUT_SCRIPT using the procedure in [https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#creating-outputs BIP352] but substituting ''a·B<sub>scan</sub>'' with the PSBT_GLOBAL_SP_ECDH_SHARE for that scan key if available, or the sum of all PSBT_IN_SP_ECDH_SHAREs from eligible inputs for that scan key.
-If there are multiple silent payment codes with the same scan key, sort the codes lexicographically in ascending order to determine the ordering of the ''k'' value.
-If there are multiple silent payment codes with both the same scan and spend keys, sort the subgroup by output index in ascending order.
+If there are multiple silent payment codes with the same scan key, assign the ''k'' values by sorting those codes in ascending order of their 66-byte serialized <tt>PSBT_OUT_SP_V0_INFO</tt> value (the concatenation of the 33-byte scan key and the 33-byte spend key). Break ties by ascending output index.
===Transaction Extractor===There was a problem hiding this comment.
I took a slightly different approach. Instead of restating the PSBT_OUT_SP_V0_INFO composition here, I clarified two terms in the per-output table (silent payment code and labeled spend key):
| <tt><33 byte scan key> <33 byte spend key></tt>
-| The scan and spend public keys from the silent payments address.
+| The scan and spend public keys from the silent payments address, referred to in this document as a ''silent payment code''. For a labeled address, the spend key is the labeled spend key ''B<sub>m</sub>''.Does this resolve the ambiguity @jonatack and @fametrano?
There was a problem hiding this comment.
A one-line addition naming the 66-byte sort key might still be helpful, not sure and it can be deferred.
|
Yes, btclib, which I maintain, followed the vectors: it assigns k per scan key in output index order (code). I ran this PR's vectors at 9514ecc through btclib's tests, and only the new three-output case fails. With k assigned by spend key, then output index, that case passes too and every invalid vector is still refused. btclib will switch to that order. I'm closing #2256 in favour of this PR and withdraw my objection to its ordering change. |
Now PSBT_OUT_SP_V0_INFO provides labeled-spend public key not the base-spend public key. Modify test vector with labeled-spend key to the same recipient from: two sp outputs - output 0 uses label=3 / output 1 uses label=1 to: three sp outputs (same scan key) - output 0 uses label=1, outputs 1 and 2 uses label=2 (same spend key) This vector excercises the BIP375 sorting outputs with same scan key properly. The next commit will fix the validation logic and address this failing test. bump ChangeLog to 0.1.3
Fix output script validation for silent payment output ordering when multiple outputs share the same scan key (labeled addresses of one recipient).
9514ecc to
d312368
Compare
Includes two changes to align the labeled test vectors and validation reference with BIP-375:
Changed vectors:
Test Runner Output